#ifndef DYN_ROOTS_NEWTONRAPHSON_H
#define DYN_ROOTS_NEWTONRAPHSON_H

#include "../utilities/dyn_functor.h"
#include "dyn_roots.h"

/*! \brief This class implements the Newton-Raphson
 * root-finding algorithm.
 *
 * We define a tolerance
 * and a maximum number of iterations to perform.
 * The solve() method applies the usual
 * formula to determine the next iteration until
 * convergence is attained.
 */

class NewtonRaphson : public RootFinding
{
public:
    /*! The constructor sets the function, derivative,
     * the initial guess along with the tolerance and the
     * maximum number of iterations to perform.
     */
    NewtonRaphson(Functor& func,
                  Functor& dfunc,
                  double initialGuess,
                  const double tol,
                  const int maxNumberIterations);

    /*! @name Specialized accessor functions.
     * Specialized accessor functions for Newton-Raphson.
     * We can access the function and the derivative.
     * Not particularly useful, but it's there.
     */
    //@{
    Functor& getFunction(){return function;}
    Functor& getDerivative(){return derivative;}

    void setFunction(Functor& func){function = func;}
    void setDerivative(Functor& dfunc){derivative = dfunc;}
    //@}

    /*! We re-declare the pure virtual function.*/
    virtual int solve();

private:
    /*! Private member variables. */
    Functor& function;
    Functor& derivative;
};

#endif // DYN_ROOTS_NEWTONRAPHSON_H
